package com.dcbeida.activity.clerkmanager;


import android.app.Activity;
import android.content.DialogInterface;
import android.support.annotation.Nullable;
import android.util.Log;
import android.widget.Toast;

import com.dcbeida.MyApplication;
import com.dcbeida.bean.Customer;
import com.dcbeida.bean.Customers;
import com.dcbeida.bean.DrugListBean;
import com.dcbeida.bean.MsgList;
import com.dcbeida.bean.ShopSummary;
import com.dcbeida.bean.ShopSummaryCurrent;
import com.dcbeida.bean.User;
import com.dcbeida.callback.DialogCallback;
import com.dcbeida.callback.JsonCallback;
import com.dcbeida.fragment.homeFragment.HomeContract;
import com.dcbeida.model.ModelUtils;
import com.dcbeida.utils.JsonGet;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.List;

import dc.medicine.com.okhttplib.OkHttpUtils;
import okhttp3.Call;
import okhttp3.Response;

/**
 * Created by hp on 2016/5/12.
 */
public class AccountListPresenter implements AccountListContract.Present {


    private AccountListContract.View view;

    private ModelUtils model;

    private Activity act;

    public AccountListPresenter(AccountListContract.View view, Activity act) {
        //我这里直接把activity作为view，所以不需要
        //mView.setPresenter(this);
        this.view = view;
        model = ModelUtils.newInstance();
        this.act = act;

    }


    @Override
    public void start() {

    }


    //取消dialog 取消请求
    DialogInterface.OnCancelListener lis = new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            model.getCancel();
        }
    };


    @Override
    public void getList(int type) {
        model.getDate("userlist", new JsonGet()
                .putopt("uid", MyApplication.user.getUid())
                .putopt("status", type)
                .tostring(), new CustomerListCallback(Customers.class));
    }


    final class CustomerListCallback<T> extends JsonCallback<T> {

        public CustomerListCallback( Type type) {
            super( type);
        }

        @Override
        public void showError(String message, int code,String data) {
            view.showTip(message);
        }

        @Override
        public void onResponse(T data) {
            if (data != null) {
                Customers customers = (Customers) data;
                view.showCustomList(customers.getList());
            }

        }


        public void onError(boolean isFromCache, Call call, @Nullable Response response, @Nullable Exception e) {
            super.onError(call, response, e);
            view.showTip("网络异常，请重试");

        }
    }


}
